package com.jty.lib_base.net

import com.czl.lib_base.config.AppConstants
import com.czl.lib_base.config.AppConstants.SpKey.ROOM_REGION
import com.czl.lib_base.config.AppConstants.SpKey.ROOM_SDK_TOKEN
import com.czl.lib_base.config.AppConstants.SpKey.TEACHER_ID
import com.czl.lib_base.config.AppConstants.SpKey.TEACHER_NAME
import com.czl.lib_base.config.AppConstants.SpKey.USER_NAME
import com.czl.lib_base.config.AppConstants.SpKey.USER_TOKEN
import com.jty.lib_base.utils.SpHelper
import com.jty.lib_base.whiteboard.WhiteboardApi
import okhttp3.Interceptor
import okhttp3.Response
import java.net.URLEncoder


/**
 * author: zhouyh
 * created on: 2021/5/12 10:15 上午
 * description:
 */
class BaseInterceptor(private val headers : Map<String,String>?):Interceptor{


    override fun intercept(chain: Interceptor.Chain): Response {
        var builder = chain.request().newBuilder()
        if (headers!=null && headers.isNotEmpty()){
            val keys = headers.keys
            for (headerKey in keys){
                builder.addHeader(headerKey,headers[headerKey]).build()
            }
        }
        //base_url 请求头
        builder.addHeader(USER_TOKEN, SpHelper.decodeString(USER_TOKEN))
//        builder.addHeader(TEACHER_ID, SpHelper.decodeInt(TEACHER_ID).toString())
//        builder.addHeader(TEACHER_NAME, URLEncoder.encode(SpHelper.decodeString(USER_NAME), "utf-8"))
//        builder.addHeader(ROOM_SDK_TOKEN,WhiteboardApi.get()?.sdkToken)
//        builder.addHeader(ROOM_REGION,AppConstants.Constants.ROOM_REGION)
        return chain.proceed(builder.build())

    }
}